/* //device/system/broncho-ril/reference-ril.c
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/

#include <telephony/ril.h>
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <pthread.h>
#include <alloca.h>
#include "atchannel.h"
#include "at_tok.h"
#include "ril_util.h"
#include <getopt.h>
#include <sys/socket.h>
//#include <cutils/sockets.h>
#include <termios.h>
#include "broncho-ril.h"

#define LOG_TAG "RIL"

#include "broncho_log.h"
#include "assert.h"

typedef void (*TestCaseCompleteFunc) (void* user_data, RIL_Errno e, void *response, size_t responselen);

typedef struct _StringValPairs
{
	int 	val;
	char*	str;
}StringValPairs;

typedef struct _RILTestContext
{
	RIL_RadioFunctions*		funcs;
	int						cmd_ref;

	int						cmd_id;
	TestCaseCompleteFunc	on_complete;
	void*					user_data;
	RIL_Errno				err;
}RILTestContext;


static RILTestContext s_RilCtx = {0};
static StringValPairs s_unsol_pairs[] = 
{
	{RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,	"RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED"},
	{RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED,		"RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED"},
	{RIL_UNSOL_RESPONSE_NETWORK_STATE_CHANGED,	"RIL_UNSOL_RESPONSE_NETWORK_STATE_CHANGED"},
	{RIL_UNSOL_RESPONSE_NEW_SMS,				"RIL_UNSOL_RESPONSE_NEW_SMS"},
	{RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT,	"RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT"},
	{RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM,			"RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM"},
	{RIL_UNSOL_ON_USSD,							"RIL_UNSOL_ON_USSD"},
	{RIL_UNSOL_ON_USSD_REQUEST,					"RIL_UNSOL_ON_USSD_REQUEST"},
	{RIL_UNSOL_NITZ_TIME_RECEIVED,				"RIL_UNSOL_NITZ_TIME_RECEIVED"},
	{RIL_UNSOL_SIGNAL_STRENGTH,					"RIL_UNSOL_SIGNAL_STRENGTH"},
	{RIL_UNSOL_PDP_CONTEXT_LIST_CHANGED,		"RIL_UNSOL_SUPP_SVC_NOTIFICATION"},
	{RIL_UNSOL_SUPP_SVC_NOTIFICATION,			"RIL_UNSOL_SUPP_SVC_NOTIFICATION"},
	{RIL_UNSOL_STK_SESSION_END,					"RIL_UNSOL_STK_SESSION_END"},
	{RIL_UNSOL_STK_PROACTIVE_COMMAND,			"RIL_UNSOL_STK_PROACTIVE_COMMAND"},
	{RIL_UNSOL_STK_EVENT_NOTIFY,				"RIL_UNSOL_STK_EVENT_NOTIFY"},
	{RIL_UNSOL_STK_CALL_SETUP,					"RIL_UNSOL_STK_CALL_SETUP"},
	{RIL_UNSOL_SIM_SMS_STORAGE_FULL,			"RIL_UNSOL_SIM_SMS_STORAGE_FULL"},
	{RIL_UNSOL_SIM_REFRESH,						"RIL_UNSOL_SIM_REFRESH"},
	{RIL_UNSOL_CALL_RING,						"RIL_UNSOL_CALL_RING"},
	{0, NULL}
};

static StringValPairs s_request_pairs[] = 
{
    {RIL_REQUEST_GET_SIM_STATUS,							"RIL_REQUEST_GET_SIM_STATUS"},
    {RIL_REQUEST_ENTER_SIM_PIN,								"RIL_REQUEST_ENTER_SIM_PIN"},
    {RIL_REQUEST_ENTER_SIM_PUK,								"RIL_REQUEST_ENTER_SIM_PUK"},	
    {RIL_REQUEST_ENTER_SIM_PIN2,							"RIL_REQUEST_ENTER_SIM_PIN2"},
    {RIL_REQUEST_ENTER_SIM_PUK2,							"RIL_REQUEST_ENTER_SIM_PUK2"},
    {RIL_REQUEST_CHANGE_SIM_PIN,							"RIL_REQUEST_CHANGE_SIM_PIN"},
    {RIL_REQUEST_CHANGE_SIM_PIN2,							"RIL_REQUEST_CHANGE_SIM_PIN2"},
    {RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION,			"RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION"},
    {RIL_REQUEST_GET_CURRENT_CALLS,							"RIL_REQUEST_GET_CURRENT_CALLS"},
    {RIL_REQUEST_DIAL,										"RIL_REQUEST_DIAL"},
    {RIL_REQUEST_GET_IMSI,									"RIL_REQUEST_GET_IMSI"},
    {RIL_REQUEST_HANGUP,									"RIL_REQUEST_HANGUP"},
    {RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND,				"RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND"},
    {RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND,		"RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND"},
    {RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE,		"RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE"},
    {RIL_REQUEST_CONFERENCE,								"RIL_REQUEST_CONFERENCE"},
    {RIL_REQUEST_UDUB,										"RIL_REQUEST_UDUB"},
    {RIL_REQUEST_LAST_CALL_FAIL_CAUSE,						"RIL_REQUEST_LAST_CALL_FAIL_CAUSE"},
    {RIL_REQUEST_SIGNAL_STRENGTH,							"RIL_REQUEST_SIGNAL_STRENGTH"},
    {RIL_REQUEST_REGISTRATION_STATE,						"RIL_REQUEST_REGISTRATION_STATE"},
    {RIL_REQUEST_GPRS_REGISTRATION_STATE,					"RIL_REQUEST_GPRS_REGISTRATION_STATE"},
    {RIL_REQUEST_OPERATOR,									"RIL_REQUEST_OPERATOR"},
    {RIL_REQUEST_RADIO_POWER,								"RIL_REQUEST_RADIO_POWER"},
    {RIL_REQUEST_DTMF,										"RIL_REQUEST_DTMF"},
    {RIL_REQUEST_SEND_SMS,									"RIL_REQUEST_SEND_SMS"},	
    {RIL_REQUEST_SEND_SMS_EXPECT_MORE,						"RIL_REQUEST_SEND_SMS_EXPECT_MORE"},
    {RIL_REQUEST_SETUP_DEFAULT_PDP,							"RIL_REQUEST_SETUP_DEFAULT_PDP"},
    {RIL_REQUEST_SIM_IO,									"RIL_REQUEST_SIM_IO"},
    {RIL_REQUEST_SEND_USSD,									"RIL_REQUEST_SEND_USSD"},
    {RIL_REQUEST_CANCEL_USSD,								"RIL_REQUEST_CANCEL_USSD"},
    {RIL_REQUEST_GET_CLIR,									"RIL_REQUEST_GET_CLIR"},
    {RIL_REQUEST_SET_CLIR,									"RIL_REQUEST_SET_CLIR"},
    {RIL_REQUEST_QUERY_CALL_FORWARD_STATUS,					"RIL_REQUEST_QUERY_CALL_FORWARD_STATUS"},
    {RIL_REQUEST_SET_CALL_FORWARD,							"RIL_REQUEST_SET_CALL_FORWARD"},
    {RIL_REQUEST_QUERY_CALL_WAITING,						"RIL_REQUEST_QUERY_CALL_WAITING"},
    {RIL_REQUEST_SET_CALL_WAITING,							"RIL_REQUEST_SET_CALL_WAITING"},
    {RIL_REQUEST_SMS_ACKNOWLEDGE,							"RIL_REQUEST_SMS_ACKNOWLEDGE"},
    {RIL_REQUEST_GET_IMEI,									"RIL_REQUEST_GET_IMEI"},
    {RIL_REQUEST_GET_IMEISV,								"RIL_REQUEST_GET_IMEISV"},
    {RIL_REQUEST_ANSWER,									"RIL_REQUEST_ANSWER"},
    {RIL_REQUEST_DEACTIVATE_DEFAULT_PDP,					"RIL_REQUEST_DEACTIVATE_DEFAULT_PDP"},
    {RIL_REQUEST_QUERY_FACILITY_LOCK,						"RIL_REQUEST_QUERY_FACILITY_LOCK"},
    {RIL_REQUEST_SET_FACILITY_LOCK,							"RIL_REQUEST_SET_FACILITY_LOCK"},
    {RIL_REQUEST_CHANGE_BARRING_PASSWORD,					"RIL_REQUEST_CHANGE_BARRING_PASSWORD"},
    {RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE,				"RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE"},
    {RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC,			"RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC"},
    {RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL,				"RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL"},
    {RIL_REQUEST_QUERY_AVAILABLE_NETWORKS,					"RIL_REQUEST_QUERY_AVAILABLE_NETWORKS"},
    {RIL_REQUEST_DTMF_START,								"RIL_REQUEST_DTMF_START"},
    {RIL_REQUEST_DTMF_STOP,									"RIL_REQUEST_DTMF_STOP"},
    {RIL_REQUEST_BASEBAND_VERSION,							"RIL_REQUEST_BASEBAND_VERSION"},
    {RIL_REQUEST_SEPARATE_CONNECTION,						"RIL_REQUEST_SEPARATE_CONNECTION"},
    {RIL_REQUEST_SET_MUTE,									"RIL_REQUEST_SET_MUTE"},
    {RIL_REQUEST_GET_MUTE,									"RIL_REQUEST_GET_MUTE"},
    {RIL_REQUEST_QUERY_CLIP,								"RIL_REQUEST_QUERY_CLIP"},
    {RIL_REQUEST_LAST_PDP_FAIL_CAUSE,						"RIL_REQUEST_LAST_PDP_FAIL_CAUSE"},
    {RIL_REQUEST_PDP_CONTEXT_LIST,							"RIL_REQUEST_PDP_CONTEXT_LIST"},
    {RIL_REQUEST_RESET_RADIO,								"RIL_REQUEST_RESET_RADIO"},
    {RIL_REQUEST_OEM_HOOK_RAW,								"RIL_REQUEST_OEM_HOOK_RAW"},
    {RIL_REQUEST_OEM_HOOK_STRINGS,							"RIL_REQUEST_OEM_HOOK_STRINGS"},
    {RIL_REQUEST_SCREEN_STATE,								"RIL_REQUEST_SCREEN_STATE"},
    {RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION,					"RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION"},
    {RIL_REQUEST_WRITE_SMS_TO_SIM,							"RIL_REQUEST_WRITE_SMS_TO_SIM"},
    {RIL_REQUEST_DELETE_SMS_ON_SIM,							"RIL_REQUEST_DELETE_SMS_ON_SIM"},
    {RIL_REQUEST_SET_BAND_MODE,								"RIL_REQUEST_SET_BAND_MODE"},
    {RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE,					"RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE"},
    {RIL_REQUEST_STK_GET_PROFILE,							"RIL_REQUEST_STK_GET_PROFILE"},
    {RIL_REQUEST_STK_SET_PROFILE,							"RIL_REQUEST_STK_SET_PROFILE"},
    {RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND,					"RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND"},
    {RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE,				"RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE"},
    {RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM,	"RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM"},
    {RIL_REQUEST_EXPLICIT_CALL_TRANSFER,					"RIL_REQUEST_EXPLICIT_CALL_TRANSFER"},
    {RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE,				"RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE"},
    {RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE,				"RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE"},
    {RIL_REQUEST_GET_NEIGHBORING_CELL_IDS,					"RIL_REQUEST_GET_NEIGHBORING_CELL_IDS"},
    {RIL_REQUEST_SET_LOCATION_UPDATES,						"RIL_REQUEST_SET_LOCATION_UPDATES"},
	{0, NULL}
};

const char* UnsolValToString (int val)
{
	int i = 0;

	while (s_unsol_pairs[i].val != 0)
	{
		if (s_unsol_pairs[i].val == val)
		{
			return s_unsol_pairs[i].str;
		}
		i++;
	}

	return NULL;
}

const char* RequestValToString (int req)
{
	int i = 0;

	while (s_request_pairs[i].val != 0)
	{
		if (s_request_pairs[i].val == req)
		{
			return s_request_pairs[i].str;
		}
		i++;
	}

	return NULL;
}

static void RIL_TestCaseLog (int req, int err)
{
	const char* req_str = RequestValToString (req);

	if (err == RIL_E_SUCCESS)
	{
		printf ("REQUESET: %s  ********SUCCESS********\n", req_str);
	}
	else
	{
		printf ("REQUESET: %s 	********FAILURE********\n", req_str);
	}

	return;
}

static void RIL_TestRequestTimedCallback (RIL_TimedCallback callback, void *param,
					const struct timeval *relativeTime)
{

	return;
}

static void RIL_TestOnUnsolicitedResponse (int unsolResponse, const void *data, size_t datalen)
{
	printf ("%s: unsolResponse=%s\n\n", __func__, UnsolValToString(unsolResponse));

	return;
}

static void RIL_TestOnRequestComplete (RIL_Token t, RIL_Errno e, void *response, size_t responselen)
{
	printf ("%s: RIL_Errno=%d \n\n", __func__, e);

	if (s_RilCtx.cmd_id != (int)t)
	{
		assert (0);
	}
	s_RilCtx.cmd_id = 0;
	if (s_RilCtx.on_complete != NULL)
	{
		s_RilCtx.on_complete (s_RilCtx.user_data, e, response, responselen);
	}
	s_RilCtx.err = e;

	return;
}

static int RIL_TestCaseFull (int request, void *data, size_t datalen, 
				TestCaseCompleteFunc on_complete, void* user_data)
{
	s_RilCtx.cmd_ref++;

	s_RilCtx.cmd_id = s_RilCtx.cmd_ref;
	s_RilCtx.on_complete = on_complete;
	s_RilCtx.user_data = user_data;
	s_RilCtx.funcs->onRequest (request, data, datalen, (void*)s_RilCtx.cmd_id);
	if (s_RilCtx.cmd_id != 0)
	{
		assert (0);
	}
	s_RilCtx.on_complete = NULL;
	s_RilCtx.user_data = NULL;
	RIL_TestCaseLog (request, s_RilCtx.err);

	return s_RilCtx.err;
}

static int RIL_TestCase (int request, void* data, size_t datalen)
{
	return RIL_TestCaseFull (request, data, datalen, NULL, NULL);
}

static void RIL_TestDev()
{
	int func[2] = {1};
	int mute[1] = {0};
	int band[1] = {1};

	RIL_TestCase(RIL_REQUEST_RADIO_POWER, func, sizeof (int));
	RIL_TestCase(RIL_REQUEST_GET_IMEI, NULL, 0);
	RIL_TestCase(RIL_REQUEST_GET_IMEISV, NULL, 0);
	RIL_TestCase(RIL_REQUEST_BASEBAND_VERSION, NULL, 0);
	RIL_TestCase(RIL_REQUEST_SET_MUTE, mute, sizeof (int));
	RIL_TestCase(RIL_REQUEST_GET_MUTE, NULL, 0);
	RIL_TestCase(RIL_REQUEST_RESET_RADIO, NULL, 0);
	sleep(30);
	RIL_TestCase(RIL_REQUEST_OEM_HOOK_RAW, NULL, 0);
	RIL_TestCase(RIL_REQUEST_OEM_HOOK_STRINGS, NULL, 0);
	RIL_TestCase(RIL_REQUEST_SET_BAND_MODE, band, sizeof (int));
	RIL_TestCase(RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE, NULL, 0);
}

static void RIL_TestMm()
{
	int screen[1] = {1};
	int plmn_index = 0;
	int updates = 2;

	RIL_TestCase(RIL_REQUEST_SIGNAL_STRENGTH, NULL, 0);
	RIL_TestCase(RIL_REQUEST_REGISTRATION_STATE, NULL, 0);
	RIL_TestCase(RIL_REQUEST_OPERATOR, NULL, 0);
	RIL_TestCase(RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE, NULL, 0);
	RIL_TestCase(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0);
	RIL_TestCase(RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL, "46000", sizeof (char*)); 
	RIL_TestCase(RIL_REQUEST_QUERY_AVAILABLE_NETWORKS, NULL, 0);
	RIL_TestCase(RIL_REQUEST_SCREEN_STATE, screen, sizeof(int));
	RIL_TestCase(RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE, &plmn_index, sizeof(int));
	RIL_TestCase(RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE, NULL, 0);
	RIL_TestCase(RIL_REQUEST_GET_NEIGHBORING_CELL_IDS, NULL, 0);
	RIL_TestCase(RIL_REQUEST_SET_LOCATION_UPDATES, &updates, sizeof (int));

	return;
}

static void RIL_TestGprs()
{
	char* pdps[3] = {"cmnet", "cmnet", "cmnet"};

	RIL_TestCase(RIL_REQUEST_GPRS_REGISTRATION_STATE, NULL, 0);
	RIL_TestCase(RIL_REQUEST_SETUP_DEFAULT_PDP, pdps, sizeof (char*) * 3);
	sleep(5);
	RIL_TestCase(RIL_REQUEST_DEACTIVATE_DEFAULT_PDP, NULL, 0); //strings
	RIL_TestCase(RIL_REQUEST_LAST_PDP_FAIL_CAUSE, NULL, 0);
	RIL_TestCase(RIL_REQUEST_PDP_CONTEXT_LIST, NULL, 0);
}

static void RIL_TestSim()
{
	char* pins[10] = {"1234", "1234"};
	
	RIL_TestCase(RIL_REQUEST_GET_SIM_STATUS, NULL, 0);
	RIL_TestCase(RIL_REQUEST_GET_IMSI, NULL, 0);

	RIL_TestCase(RIL_REQUEST_ENTER_SIM_PIN, pins, sizeof (char*));
	RIL_TestCase(RIL_REQUEST_ENTER_SIM_PUK, pins, 2 * sizeof (char*));
	RIL_TestCase(RIL_REQUEST_CHANGE_SIM_PIN, pins, 2 * sizeof (char*));

	RIL_TestCase(RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION, pins, sizeof (char*));

	//RIL_TestCase(RIL_REQUEST_CHANGE_SIM_PIN2, pins, 2 * sizeof (char*));
	//RIL_TestCase(RIL_REQUEST_ENTER_SIM_PIN2, pins, sizeof (char*));
	//RIL_TestCase(RIL_REQUEST_ENTER_SIM_PUK2, pins, 2 * sizeof (char*));

//	RIL_TestCase (RIL_REQUEST_SIM_IO, &sim_io, sizeof (RIL_SIM_IO));

	return;
}

static void RIL_TestSms()
{
	char* data[2] = {0};
	int acks[1] = {1};
	int ret = 0;
	int id = 1;
	RIL_SMS_WriteArgs sms_write = {0};

	data[1] = "01000b813127989097f9000003f97c1e";
	ret = RIL_TestCase (RIL_REQUEST_SEND_SMS, data, 2 * sizeof (char*));

	RIL_TestCase (RIL_REQUEST_SEND_SMS_EXPECT_MORE, NULL, 0);
	RIL_TestCase (RIL_REQUEST_SMS_ACKNOWLEDGE, acks, sizeof (int));

	sms_write.status = 2;
	sms_write.pdu = "01000b813127989097f9000003f97c1e";
	RIL_TestCase (RIL_REQUEST_WRITE_SMS_TO_SIM, &sms_write, sizeof (sms_write));
	RIL_TestCase (RIL_REQUEST_DELETE_SMS_ON_SIM, &id, sizeof(int));

	return;
}

static void RIL_TestSs()
{
	int cilr[1] = {0};
	int waiting[2] = {1, 7};
	char* fac_locks[4] = {"SC", "1", "1234", "0"};
	char* fac_querys[3] = {"SC", "1234", "0"};
	int cssn_flag[1] = {1};
	char* pwd[3] = {"SC", "1234", "1234"};
	int i = 0;
	int class[1] = {0};
	RIL_CallForwardInfo info = {0};

	RIL_TestCase(RIL_REQUEST_SEND_USSD, "#111#", sizeof ("#111#"));
	RIL_TestCase(RIL_REQUEST_CANCEL_USSD, NULL, 0);
	RIL_TestCase(RIL_REQUEST_GET_CLIR, NULL, 0);
	RIL_TestCase(RIL_REQUEST_SET_CLIR, cilr, sizeof (int));

	info.toa = 129;
	info.number = "13590171037";
	info.timeSeconds = 10;
	for(i = 0; i < 6; i++)
	{
		info.reason = i;
		info.status = 3;
		RIL_TestCase(RIL_REQUEST_SET_CALL_FORWARD, &info, sizeof(info));
		info.status = 0;
		RIL_TestCase(RIL_REQUEST_SET_CALL_FORWARD, &info, sizeof(info));
		info.status = 1;
		RIL_TestCase(RIL_REQUEST_SET_CALL_FORWARD, &info, sizeof(info));
		RIL_TestCase(RIL_REQUEST_QUERY_CALL_FORWARD_STATUS, &info, sizeof(info));
		info.status = 4;
		RIL_TestCase(RIL_REQUEST_SET_CALL_FORWARD, &info, sizeof(info));
	}
	RIL_TestCase(RIL_REQUEST_QUERY_CALL_WAITING, class, sizeof(class));
	RIL_TestCase(RIL_REQUEST_SET_CALL_WAITING, waiting, sizeof(waiting));
	RIL_TestCase(RIL_REQUEST_QUERY_FACILITY_LOCK, fac_querys, sizeof(fac_querys));
	RIL_TestCase(RIL_REQUEST_CHANGE_BARRING_PASSWORD, pwd, sizeof(pwd));
	RIL_TestCase(RIL_REQUEST_SET_FACILITY_LOCK, fac_locks, sizeof(fac_locks));
	fac_locks[1] = "0";
	RIL_TestCase(RIL_REQUEST_SET_FACILITY_LOCK, fac_locks, sizeof(fac_locks));
	fac_locks[1] = "2";
	RIL_TestCase(RIL_REQUEST_SET_FACILITY_LOCK, fac_locks, sizeof(fac_locks));
	RIL_TestCase(RIL_REQUEST_QUERY_CLIP, NULL, 0);
	RIL_TestCase(RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION, cssn_flag, sizeof(cssn_flag));
}

static void RIL_TestStk()
{
	RIL_TestCase(RIL_REQUEST_STK_GET_PROFILE, NULL, 0);
	RIL_TestCase(RIL_REQUEST_STK_SET_PROFILE, NULL, 0);
	RIL_TestCase(RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND, NULL, 0);
	RIL_TestCase(RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE, NULL, 0);
	RIL_TestCase(RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM, NULL, 0);
}

static void RIL_TestCc()
{
	RIL_Dial 	dial = {0};
	int			ids[2] = {0};

	RIL_TestCase (RIL_REQUEST_GET_CURRENT_CALLS, NULL, 0);
	RIL_TestCase (RIL_REQUEST_DIAL, &dial, sizeof (dial));
	RIL_TestCase (RIL_REQUEST_HANGUP, ids, sizeof (int));
	RIL_TestCase (RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND, NULL, 0);
	RIL_TestCase (RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND, NULL, 0);
	RIL_TestCase (RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE, NULL, 0);
	RIL_TestCase (RIL_REQUEST_CONFERENCE, NULL, 0);
	RIL_TestCase (RIL_REQUEST_UDUB, NULL, 0);
	RIL_TestCase (RIL_REQUEST_LAST_CALL_FAIL_CAUSE, NULL, 0);
	RIL_TestCase (RIL_REQUEST_DTMF, "1234", sizeof ("1234"));
	RIL_TestCase (RIL_REQUEST_ANSWER, NULL, 0);
	RIL_TestCase (RIL_REQUEST_DTMF_START, "", 0);
	RIL_TestCase (RIL_REQUEST_DTMF_STOP, NULL, 0);
	RIL_TestCase (RIL_REQUEST_SEPARATE_CONNECTION, NULL, 0);
	RIL_TestCase (RIL_REQUEST_EXPLICIT_CALL_TRANSFER, NULL, 0);
}

int main (int argc, char** argv)
{
	struct RIL_Env e = {0};

	e.OnUnsolicitedResponse = RIL_TestOnUnsolicitedResponse;
	e.OnRequestComplete = RIL_TestOnRequestComplete;
	e.RequestTimedCallback = RIL_TestRequestTimedCallback;

	s_RilCtx.funcs = (RIL_RadioFunctions*)RIL_Init(&e, argc, argv);
	
	sleep (30);
	RIL_TestDev();
	RIL_TestMm();
	//RIL_TestGprs();
	//RIL_TestSim();
	//RIL_TestSms();
	
	RIL_TestSs();
	/*
	RIL_TestStk();
	RIL_TestCc();
	*/

	while (1)
	{
		sleep (60);
	}

	return 0;
}


